<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/login.css">
</head>

<body>
    <div class="log-pic">
        <div class="log-box">
            <!-- 标题 -->
            <div class="log-title">
                密码登录
            </div>
            <!-- 内容 -->
            <div class="log-content">
                <div class="log-ipt1">
                    <input name="name" type="text" placeholder="用户名">
                </div>
                <div class="log-ipt2">
                    <input name="pwd" type="password" placeholder="密码">
                </div>
                <!-- 登录 -->
                 <div class="log-btn">
                    <button>登录</button>
                </div>
            </div>
        </div>
    </div>

    <script src="../tools/jquery.min.js"></script>
    <script src="../js/myAjax.js"></script>
    <script src="../js/cookie.js"></script>

    <script>
        $('button').click(function(){
        const xhr = myPromiseJQueryAjax('../server/goods_login.php' , 'post' , { userName: $('[name="name"]').val() , userPwd:  $('[name="pwd"]').val() } , 'json');
        xhr.then(function(res){
            console.log(res);
            if(res.result === 1){
                mySetCookie( 'login' , 1 , 7*24*60*60 , '/' );
                if(window.confirm('您登录成功，点击确定跳转来时候的页面')){
                    window.location.href = `${window.location.search.substr(5)}`;
                }
            }else if(res.result === 0){
                window.alert('您的账号密码有误，请您检查后重新登录');
            }
        })
        })
    </script>
</body>

</html>